package com.unitd.base.module.master.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unitd.base.module.comm.enums.DeleteFlagEnum;
import com.unitd.base.module.comm.enums.StatusEnum;
import com.unitd.base.module.master.pojo.dto.ChannelVO;
import com.unitd.base.module.master.mybatis.mapper.ChannelMapper;
import com.unitd.base.module.master.pojo.po.ChannelPO;
import com.unitd.base.module.master.service.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 频道信息处理的业务逻辑接口实现类
 *
 * @author Channel
 * @version 1.0
 * @filename ChannelServiceImpl.java
 * @copyright www.pactera.com
 * @date 2020-08-13
 */
@Slf4j
@Service
public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, ChannelPO> implements ChannelService {

    /**
     * 按照指定排序获取有效频道列表信息
     *
     * @return 指定排序的有效频道列表信息
     */
    @Override
    public List<ChannelVO> selectBySort() {

        List<ChannelPO> channels = baseMapper.selectList(new QueryWrapper<ChannelPO>()
                .eq("status", StatusEnum.ONE.getCode())
                .eq("delete_flag", DeleteFlagEnum.NO.getCode())
                .orderByAsc("sort_order"));

        return channels.stream().map(e -> {
            ChannelVO vo = new ChannelVO();
            BeanUtils.copyProperties(e, vo);
            vo.setIcon_url(e.getIconUrl())
                    .setSort_order(e.getSortOrder());
            return vo;
        }).collect(Collectors.toList());
    }
}